package miiteen.demo.web.controller;


import io.swagger.annotations.ApiOperation;
import miiteen.core.result.ResultMessage;
import miiteen.core.result.ResultMessageTool;
import miiteen.demo.web.beans.CustomsBaseInfo;
import miiteen.demo.web.beans.CustomsMediaInfo;
import miiteen.demo.web.beans.WebInfo;
import miiteen.demo.web.service.CustomsBaseInfoService;
import miiteen.demo.web.service.CustomsMediaInfoService;
import miiteen.sys.base.controller.BaseAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/demo/web/customsbaseinfo")
@CrossOrigin
public class CustomsBaseInfoController extends BaseAction {


    @Autowired
    private CustomsBaseInfoService customsBaseInfoService;

    @Autowired
    private CustomsMediaInfoService customsMediaInfoService;

    @ApiOperation("获取具体兰关动态详情")
    @RequestMapping(value="/findById",method = RequestMethod.POST)
    @ResponseBody
    public ResultMessage<Object> findById(@RequestBody WebInfo webInfo) {

        Map<String,Object> map=new HashMap<>();
        String resourceId=webInfo.getResourceId();
        if(!"".equals(resourceId)&&resourceId!=null){
            map.put("resourceId",resourceId);
        }else{
            return ResultMessageTool.Error("参数错误,resourceId不能为空");
        }
        CustomsMediaInfo customsMediaInfo=customsMediaInfoService.findById(resourceId);

        List<CustomsBaseInfo> list= customsBaseInfoService.findListByMap(map);
        map.clear();
        map.put("baseInfoList",list);
        map.put("titleInfo",customsMediaInfo);
        if(list.size()>0){
            return ResultMessageTool.Success("查询成功",map);
        }else{
            return ResultMessageTool.Error("查询失败");
        }

    }


    @ApiOperation("获取具体兰关动态详情")
    @RequestMapping("/findByIdTest")
    @ResponseBody
    public ResultMessage<Object> findByIdTest(@RequestParam String resourceId) {

        Map<String,Object> map=new HashMap<>();
        map.put("resourceId",resourceId);
        if(!"".equals(resourceId)&&resourceId!=null){
            map.put("resourceId",resourceId);
        }else{
            return ResultMessageTool.Error("参数错误,resourceId不能为空");
        }
        CustomsMediaInfo customsMediaInfo=customsMediaInfoService.findById(resourceId);

        List<CustomsBaseInfo> list= customsBaseInfoService.findListByMap(map);
        map.clear();
        map.put("baseInfoList",list);
        map.put("titleInfo",customsMediaInfo);
        if(list.size()>0){
            return ResultMessageTool.Success("查询成功",map);
        }else{
            return ResultMessageTool.Error("查询失败");
        }
    }



}
